/*******************************************************************************
 * Copyright (c) 2010, 2030 www.itlaobing.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import cn.itlaobing.model.OrderModel;
import cn.itlaobing.model.UserModel;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import javax.management.Query;


/** 
 * ClassName: UserDao <br/> 
 * Function: 用户dao层 <br/> 
 * date: 2017年11月1日 下午2:36:06 <br/> 
 * 
 * @author wd
 * @version  
 * @since JDK 1.8 
 */
public class UserDao extends BaseDao {

		
		public UserModel authentication(String username) throws SQLException {
			QueryRunner qr=new QueryRunner(getDataSource());
			String sql="select userid userId,username userName,userpass userPass,lastdate lastDate,nickname nickName,phone userPhone " +
					"from users where username=? or phone=?";
			BeanHandler<UserModel> userbeanHandler=new BeanHandler<UserModel>(UserModel.class);
			UserModel um=qr.query(sql,userbeanHandler,username,username);
			return  um;
		}
		public void updateLastTime(int id) throws SQLException {
			QueryRunner qr=new QueryRunner(getDataSource());
			String sql="update users set lastdate=now() where userid=?";
			qr.update(sql,id);
		}




		/*public UserModel findUserByNameAndPwd(String name,String pwd)throws ClassNotFoundException,SQLException{
			String sql="SELECT * FROM users WHERE username=? AND userpass=?";
			QueryRunner qr=new QueryRunner(getDataSource());
			UserModel um=qr.query(sql,new UserResultHandler(),name,pwd);
			return  um;

		}*/
}
